#! /usr/bin/python

__author__="unlotto"
__date__ ="$Mar 4, 2009 12:18:54 PM$"

import lpantilt

class CylonPanTilt():
  """Using a c-like way of doing things. The root pan and tilt functions don't have optional delay. Please notice this class' delay function """
  dev = 1 #device descriptor created at initialisation.
  def __init__(self):
    print "opening dev"
    self.dev = lpantilt.opendev("/dev/video1")
    print "dev descriptor is "+str(self.dev)

    self.cylonMode()

  def delay(self,steps):
    lpantilt.Lpantilt.delay(steps)

  def cylonMode(self):
    print "RESETTING"
    lpantilt.reset(self.dev)
    
    x = 0
    print "CYLON MODE"
    while True:
      result = lpantilt.pan(self.dev,140)
      print "lpantilt.pan + Returned "+str(result)
      self.delay(140)

      result = lpantilt.pan(self.dev,-140)
      print "lpantilt.pan - Returned "+str(result)
      self.delay(-140)

class CylonPanTiltPythonic(lpantilt.Lpantilt):
  """Using a more pythonic way of doing things. """
  def  cylonMode(self):
    print "RESETTING"
    self.reset()
    print "CYLON MODE"
    while True:
      result = self.pan(140)
      print "self.pan + Returned "+str(result[0])+" with number of fails: "+str(result[1])

      result = self.pan(-140)
      print "self.pan - Returned "+str(result[0])+" with number of fails: "+str(result[1])


if __name__ == "__main__":
    #lpt = CylonPanTilt()
    lpt = CylonPanTiltPythonic("/dev/video1")
    lpt.cylonMode()
